//
//  AppDelegate.m
//  CropImg
//
//  Created by lipeng on 16/3/7.
//  Copyright © 2016年 lipeng. All rights reserved.
//

#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    
//    [application cancelAllLocalNotifications];
//    
//    //申请用户的许可
//    float version=[[[UIDevice currentDevice]systemVersion]floatValue];
//    if (version>8.0) {
//        UIUserNotificationSettings *setting=[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeSound|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil];
//        [[UIApplication sharedApplication]registerUserNotificationSettings:setting];
//    }
//    UILocalNotification *localNotification=[launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
//    if (localNotification!=nil) {
//        [self processLocationNotification:localNotification];
//    }
    
    
    
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

-(void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
    if(notificationSettings.types != UIUserNotificationTypeNone)
    {
        //注册本地推送  首先是生成UILocalNotification对象
        UILocalNotification *localNotification = [[UILocalNotification alloc]init];
        //提示触发的时间
        localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:5];
        //提示推送的内容
        localNotification.alertBody=@"这是一个本地推送测试";
//        localNotification.repeatInterval=3;
        localNotification.repeatInterval=NSCalendarUnitHour;
        //定制消息到来时候播放的声音文件  一定要在Bunddle内，而且声音的持续时间不能超过30s
        localNotification.soundName=UILocalNotificationDefaultSoundName;
        //设置系统角标
        localNotification.applicationIconBadgeNumber=6;
        //注册本地通知到系统中，这样系统到指定的时间会触发该通知
        [[UIApplication sharedApplication]scheduleLocalNotification:localNotification];
    }
}

-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
    //判断应用程序状态来决定是否弹框
//    if (application.applicationState == UIApplicationStateActive) {
//        UIAlertView *alterView = [[UIAlertView alloc]initWithTitle:@"本地推送" message:notification.alertBody delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil];
//        [alterView show];
//    }else if (application.applicationState == UIApplicationStateInactive)
//    {
//        NSLog(@"UIApplicationStateInactive");
//    }else{
//        //background
//        NSLog(@"UIApplicationStateBackground");
//    }
}

- (void)processLocationNotification:(UILocalNotification *)localNotification{
    UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"lanchApp" message:@"loc" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alertView show];
}

@end
